package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.TextView;

public class Event extends Activity {

	private TextView textEvent;
	private GestureDetector detector =	null;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event);
		
		textEvent =	(TextView)findViewById(R.id.textEvents);
		
		View layout =	findViewById(R.id.rootLayout);
		ViewTreeObserver observer =	layout.getViewTreeObserver();
		observer.addOnTouchModeChangeListener(new ViewTreeObserver.OnTouchModeChangeListener() {
			@Override
			public void onTouchModeChanged(boolean isInTouchMode) {
				textEvent.append("\nTouceModeChanged : " + isInTouchMode);
			}
		});
		
		textEvent.setOnLongClickListener(new View.OnLongClickListener() {
			@Override
			public boolean onLongClick(View v) {
				textEvent.append("\nonLongChick : " + v.toString());
				return true;
			}
		});
		
		detector =	new GestureDetector(
			new GestureDetector.SimpleOnGestureListener() {
				public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
					textEvent.append("\nonFling\tx = " + velocityX + "\ty = " + velocityY);
					return super.onFling(e1, e2, velocityX, velocityY);
				}
				
				public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
					textEvent.append("\nonScroll\tx = " + distanceX + "\ty = " + distanceY);
					return super.onScroll(e1, e2, distanceX, distanceY);
				}
			}
		); 
		
		textEvent.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				textEvent.append("\nonFocusChange, hasFocus : " + hasFocus);
			}
		});

	}
	
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (detector != null) {
			return detector.onTouchEvent(event);
		} else {
			return super.onTouchEvent(event);
		}
	}

}
